package com.example.home.youthstation;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.home.R;
import com.example.home.tool.OKHttpTool;

import java.util.ArrayList;
import java.util.List;

public class HostelDetailActivity extends AppCompatActivity {

    private String dataBeanID;
    private ViewPager photoViewPager;
    private TextView addressTextView;
    private TextView contactTextView;
    private TextView checkInTimeTextView;
    private TextView bedsTextView;
    private TextView introductionTextView;
    private TextView roomTextView;
    private TextView facilitiesTextView;
    private TextView servicesTextView;
    private TextView bedsCountGirlTextView;
    private Hostel_DetailBean hostel_detailBean;
    private List<String> list_img ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hostel_detail);
        Intent intent = getIntent();
        dataBeanID = intent.getStringExtra("RowsBeanId");
        initview();
        getBean(hostel_detailBean);

    }

    private void getBean(Hostel_DetailBean hostel_detailBean) {
        OKHttpTool.doNetRequest("prod-api/api/youth-inn/youth-inn/"+dataBeanID,
                OKHttpTool.GET,
                Hostel_DetailBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        Hostel_DetailBean hostel_detailBean = (Hostel_DetailBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                addressTextView.setText("驿站地址:"+hostel_detailBean.getData().getAddress());
                                contactTextView.setText("联系电话:"+hostel_detailBean.getData().getPhone());
                                checkInTimeTextView.setText("办理入住时间段:"+hostel_detailBean.getData().getWorkTime());
                                bedsTextView.setText("剩余床位数：男:"+String.valueOf(hostel_detailBean.getData().getBedsCountBoy()));
                                bedsCountGirlTextView.setText("剩余床位数：女:"+String.valueOf(hostel_detailBean.getData().getBedsCountGirl()));
                                introductionTextView.setText("驿站简介:"+hostel_detailBean.getData().getIntroduce());
                                roomTextView.setText("房间配置:"+hostel_detailBean.getData().getInternalFacilities());
                                facilitiesTextView.setText("周边配套:"+hostel_detailBean.getData().getSurroundingFacilities());
                                servicesTextView.setText("特色服务:"+hostel_detailBean.getData().getSpecialService());

                                PhotoViewPagerApter photoViewPagerApter = new PhotoViewPagerApter(HostelDetailActivity.this,hostel_detailBean.getData().getImageUrlList());
                                photoViewPager.setAdapter(photoViewPagerApter);
                                mHandler.sendEmptyMessageDelayed(0, 3 * 500);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {
                        Log.v("xhf","访问失败");
                    }
                }
        );
    }

    private void initview() {
        list_img = new ArrayList<>();


        photoViewPager = findViewById(R.id.photoViewPager);
        addressTextView = findViewById(R.id.addressTextView);
        contactTextView = findViewById(R.id.contactTextView);
        checkInTimeTextView = findViewById(R.id.checkInTimeTextView);
        bedsCountGirlTextView = findViewById(R.id.bedsCountGirlTextView);
        bedsTextView = findViewById(R.id.bedsTextView);
        introductionTextView = findViewById(R.id.introductionTextView);
        roomTextView = findViewById(R.id.roomTextView);
        facilitiesTextView = findViewById(R.id.facilitiesTextView);
        servicesTextView = findViewById(R.id.servicesTextView);
    }

    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            if (msg.what == 0) {
                int index = photoViewPager.getCurrentItem();
                index = (index + 1) % 7;
                photoViewPager.setCurrentItem(index);
                mHandler.sendEmptyMessageDelayed(0, 3 * 500);
            }
        }
    };
}